<?php
pc_base::load_app_class('hchbase','hchindex',0);
class position extends hchbase {
    function __construct() {
        parent::__construct();
        $this->db = pc_base::load_model("myjob_model"); //连接数据库
        $this->memberdb = pc_base::load_model("member_model");
        $this->bulletInfo0 = '华创俱乐部 HCCLUB';
        $this->bulletInfo1 = '人才对接';
        $this->bulletInfo2 = '招聘职位';
    }
    //发布或编辑职位
    function publish(){ 
        $userid = param::get_cookie('_userid');
        if(empty($userid)){
            showmessage('请先登录！','/index.php?m=hchmember&c=index&a=login');
        }else{

        $jobid = $_REQUEST['jobid'];
        // 获取职位类别
        $position_list = $this->get_position();
        // 获取行业类别
        $industry_list = $this->get_industry();
        // 获取省
        $province_list = $this->get_area();
        $work_years_list = array(1,2,3,4,5,6,7,8,9,10);
        $column_name = '发布新职位';
        // 默认加载联系方式
        $item = $this->memberdb->get_one(array('userid' => $userid),'`username` as `link_man`,`mobile` as `link_tel`,`email` as `link_mail`');
        // 进入修改状态
        if(isset($jobid) && is_numeric($jobid)){
            $where = array('id' => $jobid);
            $item = $this->db->get_one($where);
            $item['end_time'] = isset($item['end_time'])?date('Y-m-d',strtotime($item['end_time'])):'';
            $column_name = '编辑职位';
        }

        include template('hr','position'); //替换模板
        }
    }

    //增加或修改
    function save(){
        $userid = param::get_cookie('_userid');
        if(empty($userid)){
            showmessage('请先登录！','/index.php?m=hchmember&c=index&a=login');
        }else{
        //请求参数
        if(!is_numeric($_POST['position']) || !is_numeric($_POST['position2']) || !is_numeric($_POST['industry']) || !is_numeric($_POST['industry2']) || !is_numeric($_POST['province']) || !is_numeric($_POST['city']) || !is_numeric($_POST['job_num'])){
            showmessage('参数有误，请重试！','/index.php?m=hchhr&c=position&a=publish');
        }
        $jobid = $_REQUEST['jobid'];
        $item['job_name']=htmlspecialchars(strip_tags($_POST['job_name'])); //职位名称
        $item['position_no']=$_POST['position']; //职位大类ID
        $item['position_name']=htmlspecialchars(strip_tags($_POST['position_name'])); //职位大类名称
        $item['position2_no']=$_POST['position2']; //职位小类ID
        $item['position2_name']=htmlspecialchars(strip_tags($_POST['position2_name'])); //职位小类名称

        $item['industry_no']=$_POST['industry']; //行业大类ID
        $item['industry_name']=htmlspecialchars(strip_tags($_POST['industry_name'])); //行业大类名称
        $item['industry2_no']=$_POST['industry2']; //行业小类ID
        $item['industry2_name']=htmlspecialchars(strip_tags($_POST['industry2_name'])); //行业小类名称
        $item['province']=htmlspecialchars(strip_tags($_POST['province_name'])); //省份名称
        $item['province_no']=$_POST['province']; //省份ID
        $item['city']=htmlspecialchars(strip_tags($_POST['city_name'])); //城市名称
        $item['city_no']=$_POST['city']; //城市ID

        $item['salary']=htmlspecialchars(strip_tags($_POST['job_money'])); //月薪范围
        list($item['salary_start'],$item['salary_end'])=explode('-',$_POST['job_money'],2);//月薪下限、上限
        $item['salary_start']=is_numeric($item['salary_start'])?$item['salary_start']:0;
        $item['salary_end']=is_numeric($item['salary_end'])?$item['salary_end']:0;

        $item['job_type']=htmlspecialchars(strip_tags($_POST['job_nature'])); //工作性质
        $item['job_desc']=htmlspecialchars($_POST['job_desc']); //职位描述
        $item['work_years']=$_POST['job_age']; //工作年限
        $item['education']=$_POST['job_edu']; //学历要求
        $item['number']=$_POST['job_num']; //招聘人数
        $item['tag']=isset($_POST['job_welfare'])?htmlspecialchars(strip_tags(str_replace('，',',',$_POST['job_welfare']))):''; //公司福利
        $item['end_time']=htmlspecialchars(strip_tags($_POST['job_endtime'])); //发布截止日期
        $item['link_man']=htmlspecialchars(strip_tags($_POST['job_linkman'])); //联系人姓名
        $item['link_tel']=htmlspecialchars(strip_tags($_POST['job_tel'])); //联系方式
        $item['link_mail']=htmlspecialchars(strip_tags($_POST['job_email'])); //联系邮箱
        $item['is_show']=1;
        $item['company_id']=$userid;
        if(isset($jobid) && is_numeric($jobid)){ //修改
            $item['last_updated_time']=date('Y-m-d H:i:s',time());
            $this->db->update($item, $where = 'id = '.$jobid);
            showmessage('修改成功！','/index.php?m=hchhr&c=position&a=publish&jobid='.$jobid);
        }
        else{ //添加
            $item['created_time']=date('Y-m-d H:i:s',time());
			$item['last_updated_time']=date('Y-m-d H:i:s',time());
			if($this->db->insert($item,true)){
                showmessage('发布成功！','/index.php?m=hchhr&c=position&a=publish');

            }
            else{
                showmessage('发布失败，请重试！','/index.php?m=hchmember&c=index&a=publish');
            }
        }

        }
    }
    // 异步获取城市用
    function load_city(){
        $parent_no = isset($_GET['parent_no'])?$_GET['parent_no']:0;
        $city = $this->get_area($parent_no,'json');
        echo $city;
    }
}
?>